"use strict";
cc._RF.push(module, '19d5beQmclNiqEAxigiYAKv', 'level_peopleArchery_ResultPage');
// scripts/levelBundles/level_PeopleArchery/page/level_peopleArchery_ResultPage.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
Object.defineProperty(exports, "__esModule", { value: true });
var PageBase_1 = require("../../../Game/Base/PageBase");
var Enum_1 = require("../../../Game/Enum");
var MainRoot_1 = require("../../../Game/MainRoot");
var gameConfig_1 = require("../../../engines/configs/gameConfig");
var gameEngine_1 = require("../../../engines/gameEngine");
var userInterface_1 = require("../../../engines/services/userContent/userInterface");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var level_peopleArchery_ResultPage = /** @class */ (function (_super) {
    __extends(level_peopleArchery_ResultPage, _super);
    function level_peopleArchery_ResultPage() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.lbKillCount = null;
        _this.lbDammage = null;
        _this.lbTime = null;
        _this.loseLayout = null;
        _this.winLayout = null;
        _this.evaluateSps = [];
        _this.evaluateSp = null;
        _this.lightSp = null;
        _this.lightSps = [];
        _this.resetBtn = null;
        _this.level = null;
        _this.winFlag = false;
        return _this;
    }
    level_peopleArchery_ResultPage.prototype.bindData = function (level, winFlag) {
        this.level = level;
        this.winFlag = winFlag;
        this.refrenshPage();
        this.resetBtn.active = false;
        // if(O1HD.getManagers().peopleArcheryManager.getData().infinityLevel >= Object.keys((O1HD.getManagers().csvDataManager.getCsvData(CsvFileKind.CsvFile.peopleArcheryInfinityEnemyHp)["title"])).length - 1){
        //     this.resetBtn.active = true;
        // }else if(!this.winFlag && this.level.getLevelInfo().infinityFlag){
        //     this.resetBtn.active = true;
        // }
        this.node.zIndex = cc.macro.MAX_ZINDEX;
    };
    level_peopleArchery_ResultPage.prototype.refrenshPage = function () {
        this.lbKillCount.string = this.level.killCount.toString();
        this.lbDammage.string = Math.floor(this.level.damage).toString();
        this.lbTime.string = Math.floor(this.level.gameTime / 60) + "分" + Math.floor(this.level.gameTime % 60) + "秒";
        var wave = this.level.realWave + 1;
        var index = 0;
        if (wave <= 3) {
            index = 0;
        }
        else if (wave <= 10) {
            index = 1;
        }
        else if (wave <= 15) {
            index = 2;
        }
        else if (wave <= 20) {
            index = 3;
        }
        else if (wave <= 30) {
            index = 4;
        }
        else if (wave <= 40) {
            index = 5;
        }
        else {
            index = 6;
        }
        this.evaluateSp.spriteFrame = this.evaluateSps[index];
        this.winLayout.active = this.winFlag;
        this.loseLayout.active = !this.winFlag;
        this.evaluateSp.node.scale = 1.5;
        cc.tween(this.evaluateSp.node).to(0.2, { scale: 1 }, { easing: cc.easing.backOut }).start();
        this.lightSp.spriteFrame = this.winFlag ? this.lightSps[0] : this.lightSps[1];
        this.lightAni();
        // if(this.winFlag){
        // let moneyNum:number = Number(this.level.peopleArcheryData["complete_money"]);
        // let addition:number = moneyNum * this.level.role.goldAddition;
        // O1HD.getManagers().peopleArcheryManager.setData({money:moneyNum + addition},true);
        // }
    };
    level_peopleArchery_ResultPage.prototype.lightAni = function () {
        var tween = cc.tween(this.lightSp.node).by(3, { angle: 360 });
        cc.tween(this.lightSp.node).repeatForever(tween).start();
    };
    level_peopleArchery_ResultPage.prototype.onBtnBackMain = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        gameEngine_1.default.getManagers().soundMgr.playSound("mainSound/anNiu");
                        return [4 /*yield*/, gameEngine_1.default.getManagers().gameMgr.returnMainScene()];
                    case 1:
                        _a.sent();
                        MainRoot_1.default.UISystem.CloseAllPage();
                        MainRoot_1.default.UISystem.OpenPage(Enum_1.PAGE.PEOPLE_ARCHERY_START_PAGE);
                        return [2 /*return*/];
                }
            });
        });
    };
    level_peopleArchery_ResultPage.prototype.onBtnAlive = function () {
        var _this = this;
        gameEngine_1.default.getManagers().soundMgr.playSound("mainSound/anNiu");
        if (gameEngine_1.default.getServices().userSrv.getCoins() > 0) {
            gameEngine_1.default.getServices().userSrv.setCoins(-1, true);
            this.level.peopleAlive();
            this.closeThis();
        }
        else {
            gameEngine_1.default.getServices().miniGameSrv.getAppApiInstance().loadAndShowVideoAd(function () {
                _this.level.peopleAlive();
                _this.closeThis();
            }, function () {
            }, null, "看广告复活");
        }
    };
    level_peopleArchery_ResultPage.prototype.onBtnAgain = function () {
        return __awaiter(this, void 0, void 0, function () {
            var needPower;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        needPower = this.level.getLevelInfo()["subPower"] || 1;
                        if (gameEngine_1.default.getServices().userSrv.getPower() - needPower < 0) {
                            MainRoot_1.default.UIModel.showUserPropGet(userInterface_1.REWARD_TYPE.POWER, gameConfig_1.default.ADD_ONCE_POWER);
                            return [2 /*return*/];
                        }
                        gameEngine_1.services().userSrv.setPower(-needPower, true, true);
                        // mainRoot.LevelSystem.AddLevel(this.m_mode, -1);
                        return [4 /*yield*/, MainRoot_1.default.UISystem.ClosePage(Enum_1.PAGE.PEOPLE_ARCHERY_INGAME_PAGE)];
                    case 1:
                        // mainRoot.LevelSystem.AddLevel(this.m_mode, -1);
                        _a.sent();
                        return [4 /*yield*/, MainRoot_1.default.LevelSystem.LoadLevel(MainRoot_1.default.LevelSystem.GetSignleLevelInfo(this.m_mode).bundleName, this.m_mode, null, true, this.level.getLevelInfo().infinityFlag ? this.level.getLevelInfo() : null)];
                    case 2:
                        _a.sent();
                        this.closeThis();
                        return [2 /*return*/];
                }
            });
        });
    };
    level_peopleArchery_ResultPage.prototype.onBtnResetInfinity = function () {
        return __awaiter(this, void 0, void 0, function () {
            var page;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        gameEngine_1.default.getManagers().soundMgr.playSound("mainSound/anNiu");
                        return [4 /*yield*/, MainRoot_1.default.UISystem.OpenPage(Enum_1.PAGE.LEVEL_PEOPLE_ARCHERY_RESETINFINITYPAGE)];
                    case 1:
                        page = _a.sent();
                        page.bindPage(this);
                        return [2 /*return*/];
                }
            });
        });
    };
    level_peopleArchery_ResultPage.prototype.onResetInfinity = function () {
        return __awaiter(this, void 0, void 0, function () {
            var needPower;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        gameEngine_1.default.getManagers().soundMgr.playSound("mainSound/anNiu");
                        needPower = this.level.getLevelInfo()["subPower"] || 1;
                        if (gameEngine_1.default.getServices().userSrv.getPower() - needPower < 0) {
                            MainRoot_1.default.UIModel.showUserPropGet(userInterface_1.REWARD_TYPE.POWER, gameConfig_1.default.ADD_ONCE_POWER);
                            return [2 /*return*/];
                        }
                        gameEngine_1.services().userSrv.setPower(-needPower, true, true);
                        gameEngine_1.default.getManagers().peopleArcheryManager.setData({ curInfinityLevel: 0 }, false);
                        return [4 /*yield*/, MainRoot_1.default.UISystem.CloseAllPage()];
                    case 1:
                        _a.sent();
                        return [4 /*yield*/, MainRoot_1.default.LevelSystem.LoadLevel(MainRoot_1.default.LevelSystem.GetSignleLevelInfo(this.m_mode).bundleName, this.m_mode, null, true, this.level.getLevelInfo().infinityFlag ? this.level.getLevelInfo() : null)];
                    case 2:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    level_peopleArchery_ResultPage.prototype.onBtnNext = function () {
        return __awaiter(this, void 0, void 0, function () {
            var needPower;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        gameEngine_1.default.getManagers().soundMgr.playSound("mainSound/anNiu");
                        needPower = this.level.getLevelInfo()["subPower"] || 1;
                        if (gameEngine_1.default.getServices().userSrv.getPower() - needPower < 0) {
                            MainRoot_1.default.UIModel.showUserPropGet(userInterface_1.REWARD_TYPE.POWER, gameConfig_1.default.ADD_ONCE_POWER);
                            return [2 /*return*/];
                        }
                        gameEngine_1.services().userSrv.setPower(-needPower, true, true);
                        return [4 /*yield*/, MainRoot_1.default.UISystem.ClosePage(Enum_1.PAGE.PEOPLE_ARCHERY_INGAME_PAGE)];
                    case 1:
                        _a.sent();
                        if (this.level.getLevelInfo()["infinityFlag"]) {
                        }
                        return [4 /*yield*/, MainRoot_1.default.LevelSystem.LoadLevel(MainRoot_1.default.LevelSystem.GetSignleLevelInfo(this.m_mode).bundleName, this.m_mode, null, true, this.level.getLevelInfo().infinityFlag ? this.level.getLevelInfo() : null)];
                    case 2:
                        _a.sent();
                        this.closeThis();
                        return [2 /*return*/];
                }
            });
        });
    };
    level_peopleArchery_ResultPage.prototype.closeThis = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                _super.prototype.ClosePage.call(this);
                return [2 /*return*/];
            });
        });
    };
    __decorate([
        property({ type: cc.Label, tooltip: "击杀怪物数量文本" })
    ], level_peopleArchery_ResultPage.prototype, "lbKillCount", void 0);
    __decorate([
        property({ type: cc.Label, tooltip: "造成伤害文本" })
    ], level_peopleArchery_ResultPage.prototype, "lbDammage", void 0);
    __decorate([
        property({ type: cc.Label, tooltip: "时间文本" })
    ], level_peopleArchery_ResultPage.prototype, "lbTime", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "失败界面" })
    ], level_peopleArchery_ResultPage.prototype, "loseLayout", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "胜利界面" })
    ], level_peopleArchery_ResultPage.prototype, "winLayout", void 0);
    __decorate([
        property({ type: cc.SpriteFrame, tooltip: "评级图片" })
    ], level_peopleArchery_ResultPage.prototype, "evaluateSps", void 0);
    __decorate([
        property({ type: cc.Sprite, tooltip: "评级图片" })
    ], level_peopleArchery_ResultPage.prototype, "evaluateSp", void 0);
    __decorate([
        property({ type: cc.Sprite, tooltip: "光效节点" })
    ], level_peopleArchery_ResultPage.prototype, "lightSp", void 0);
    __decorate([
        property({ type: cc.SpriteFrame, tooltip: "光效图片" })
    ], level_peopleArchery_ResultPage.prototype, "lightSps", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "重置按钮" })
    ], level_peopleArchery_ResultPage.prototype, "resetBtn", void 0);
    level_peopleArchery_ResultPage = __decorate([
        ccclass
    ], level_peopleArchery_ResultPage);
    return level_peopleArchery_ResultPage;
}(PageBase_1.default));
exports.default = level_peopleArchery_ResultPage;

cc._RF.pop();